package com.example.brainmemory.ui;

import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import com.example.brainmemory.R;

public class GameButton extends android.widget.Button {
	public static int buttonCount = 0;
	// TODO: move layout to xml ...
	/*
	 * Static informations
	 */
	private static final int buttonIdStart = 1000;
	/*
	 * private informations
	 */
	private int buttonId = 0;

	private Context con;

	public GameButton(Context context, OnClickListener listener, int edgeLength) {
		super(context);
		con = context;
		buttonCount++;
		this.setWidth(edgeLength);
		this.setHeight(edgeLength);
		this.setId(buttonIdStart + buttonCount);
		this.setBackgroundColor(Color.WHITE);
		this.setTextColor(Color.BLACK);
		this.setOnClickListener(listener);
		this.buttonId = buttonCount;
		this.setText(" " + buttonCount);
	}

	public int getButtonId() {
		return this.buttonId;
	}

	/*
	 * TODO: add animation
	 */
	public void showAnimated(Animation anim, boolean visibleAfterAnim) {
		this.setAnimation(anim);
		this.startAnimation(anim);
        
		if (visibleAfterAnim)
			return;
		
		final GameButton current = this;
		new Handler().postDelayed(new Runnable() { 
                @Override
                public void run() {
                	current.setVisibility(INVISIBLE);
                }
        }, anim.getDuration());
		
	}
}
